# -*- mode: snippet -*-
# name: ggplot geom_boxplot template
# key: ggplot2.geom_boxplot.template
# key: geom_boxplot.template@ggplot2
# contributor: Shuguang Sun
# --
# library(hrbrthemes)
# library(viridis)
ggplot(${1:dt}, aes(x = ${2:as.factor(${3:x})}, y = ${4:y})) + # define x and y axis variables
  geom_boxplot(
  # notch: Useful to compare groups:
  # if no overlap between 2 groups, medians are significantly different.
  # notch = TRUE,
  # position = position_dodge(1), # for grouped boxplot
  # outlier.shape = NA, # hide outlier
  # Change outlier, color, shape and size
  outlier.colour = "red",
  outlier.shape = 8,
  outlier.size = 4) +
  stat_summary(
  # Box plot with mean points
  fun = mean,
  geom = "point",
  shape = 23,
  size = 4) +
  # scale_fill_viridis(discrete = TRUE, alpha=0.6) +
  # geom_dotplot(binaxis='y', stackdir='center', dotsize=0.3) + # Box plot with dot plot
  # Box plot with jittered points
  geom_jitter(color = "black", size = 1, alpha = 0.9, shape = 16, position=position_jitter(0.2)) +
  # coord_flip() + # Rotate the box plot
  scale_x_discrete(limits=c("20", "40")) + # Choose which factors to display
  labs(x = "", y = "")
